﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AttributeRouting;
using AttributeRouting.Web.Mvc;
using PH.Model.Webs;
using PH.Logic.Webs;
namespace PH.Web.Management.Areas.Portal.Controllers
{
    [RouteArea("Portal")]
    public class GeneralController : Controller
    {
        [Route("",IgnoreAreaUrl=true)]
        public ActionResult Index()
        {
            ViewBag.News = PageLogic.Gets(new PageQuery() { CaseID = 2 }).Take(5).ToList();
            return View();
        }

        [Route("Nav")]
        public ActionResult Nav()
        {
            ViewBag.Case = CaseLogic.GetTopCaseByFriendUrl(Request.Path);
            var lst = CaseLogic.Gets(new CaseQuery() { PID = null, GetItems = true });
            return PartialView("_Nav", lst);
        }

        [Route("SubNav")]
        public ActionResult SubNav()
        {
            var cas = CaseLogic.GetTopCaseByFriendUrl(Request.Path);
            return PartialView("_LeftSubNav", cas);
        }

        [Route("PicList")]
        public ActionResult PicList()
        {
            var cas = CaseLogic.GetCaseByFriendUrl(Request.Path);
            if (cas.ParentCase == null)
                cas = CaseLogic.GetCaseByParent(cas);
            ViewBag.Case = cas;
            return View();
        }

        [Route("News")]
        [Route("TxtList")]
        public ActionResult TxtList()
        {
            var cas = CaseLogic.GetCaseByFriendUrl(Request.Path);
            //if (cas.ParentCase == null)
            //    cas = CaseLogic.GetCaseByParent(cas);
            ViewBag.Case = cas;
            return View();
        }

        [Route("Article/{id:int?}")]
        public ActionResult Article(int id = 0)
        {
            var cas = CaseLogic.GetCaseByFriendUrl(Request.Path);
            if (cas != null)
            {
                if (cas.ParentCase == null)
                    cas = CaseLogic.GetCaseByParent(cas);
                ViewBag.Case = cas;
            }
            
            PageModel model = null;
            if (id > 0)
                model = PageLogic.GetPage(id);
            else if (cas != null)
                model = PageLogic.GetTopPage(cas.ID);

            return View(model);
        }
    }
}
